package com.example.controller;

import com.example.common.Result;
import com.example.entity.GridType;
import com.example.service.GridTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.util.List;
/**
*  基础元素类型的控制层
**/
@RestController
@RequiredArgsConstructor
@RequestMapping("/gridType")
public class GridTypeController {

   private final GridTypeService gridTypeService;

   /**
   * 增
   **/
   @PostMapping("/add")
   public Result add(@RequestBody GridType gridType) {
       gridTypeService.add(gridType);
       return Result.success();
   }

   /**
   * 删
   **/
   @DeleteMapping("/delete/{id}")
   public Result deleteById(@PathVariable Integer id) {
       gridTypeService.deleteById(id);
       return Result.success();
   }

   /**
   * 批量删除
   **/
   @DeleteMapping("/delete/batch")
   public Result deleteBatch(@RequestBody List<Integer> ids) {
       gridTypeService.deleteBatch(ids);
       return Result.success();
   }

   /**
   * 改
   **/
   @PutMapping("/update")
   public Result updateById(@RequestBody GridType gridType) {
       gridTypeService.updateById(gridType);
       return Result.success();
   }

   /**
   * 根据ID查询
   **/
   @GetMapping("/selectById/{id}")
   public Result selectById(@PathVariable Integer id) {
       GridType gridType = gridTypeService.selectById(id);
       return Result.success(gridType);
   }

   /**
   * 查询所有
   **/
   @GetMapping("/selectAll")
       public Result selectAll(GridType gridType ) {
       List<GridType> list = gridTypeService.selectAll(gridType);
       return Result.success(list);
   }

   /**
   * 分页查询
   **/
   @GetMapping("/selectPage")
   public Result selectPage(GridType gridType,
   @RequestParam(defaultValue = "1") Integer pageNum,
   @RequestParam(defaultValue = "10") Integer pageSize) {
   PageInfo<GridType> page = gridTypeService.selectPage(gridType, pageNum, pageSize);
       return Result.success(page);
   }

}